package org.dei.perla.rockfall.gui.queryforge;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

class GainsStatusPanel extends JPanel implements ParameterConfigurationManipulator {
	
	private DSPicParameters parameters;
	private GainsStatusGeophoneXPanel gsxPanel;
	private GainsStatusGeophoneYPanel gsyPanel;
	private GainsStatusGeophoneZPanel gszPanel;
	private GainsStatusMemsXPanel msxPanel;
	private GainsStatusMemsYPanel msyPanel;
	private GainsStatusMemsZPanel mszPanel;
	private GainsSwitchPanel gsPanel;
	private CrackBiasPanel crkPanel;

public GainsStatusPanel() {
		super();
		BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS);
		this.setLayout(layout);
		gsxPanel = new GainsStatusGeophoneXPanel("GX");
		gsyPanel = new GainsStatusGeophoneYPanel("GY");
		gszPanel = new GainsStatusGeophoneZPanel("GZ");
		msxPanel = new GainsStatusMemsXPanel("MX");
		msyPanel = new GainsStatusMemsYPanel("MY");
		mszPanel = new GainsStatusMemsZPanel("MZ");
		gsPanel = new GainsSwitchPanel("Gains Switches");
		crkPanel = new CrackBiasPanel("Crackmeter Bias");
		this.add(gsxPanel);
		this.add(gsyPanel);
		this.add(gszPanel);
		this.add(msxPanel);
		this.add(msyPanel);
		this.add(mszPanel);
		this.add(gsPanel);
		this.add(crkPanel);
	}

public GainsStatusPanel(DSPicParameters parameters) {
	this();
	this.parameters = parameters;
}

public void updateConfiguration() {
	gsxPanel.setStatus(this.parameters.getGx());
	gsyPanel.setStatus(this.parameters.getGy());
	gszPanel.setStatus(this.parameters.getGz());
	msxPanel.setStatus(this.parameters.getMx());
	msyPanel.setStatus(this.parameters.getMy());
	mszPanel.setStatus(this.parameters.getMz());
	gsPanel.setStatus(this.parameters.getRs4());
	crkPanel.setStatus(this.parameters.getCrackBias());
}

@Override
public void readConfiguration() throws IllegaParamValueException {
	// TODO Auto-generated method stub
	if(this.parameters != null){
		this.parameters.setGx(gsxPanel.getStatus());
		this.parameters.setGy(gsyPanel.getStatus());
		this.parameters.setGz(gszPanel.getStatus());
		this.parameters.setMx(msxPanel.getStatus());
		this.parameters.setMy(msyPanel.getStatus());
		this.parameters.setMz(mszPanel.getStatus());	
		this.parameters.setRs4(parameters.getRs4() | gsPanel.getStatus());
		this.parameters.setCrackBias(crkPanel.getStatus());
	}
}



}
